package week4;

import javax.swing.*;
import java.awt.*;

/**
 * @author The Setting sun
 * @create 2021-09-29 9:32
 */
public class code {
    public static void main(String[] args) {
        JFrame jf = new JFrame();

        class MyPaint extends JPanel{
            @Override
            public void paint(Graphics g) {
                g.setColor(Color.GRAY);
                g.fillRect(0, 0, 500, 100);

                g.setColor(Color.BLACK);
                g.drawRect(0, 0, 500, 100);

                g.setColor(Color.yellow);
                for (int i = 0; i < 100; i++) {
                    g.drawOval((int)(Math.random() * 499 + 1), (int)(Math.random() * 100 + 1), 5, 5);
                }

                String str = "0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM";
                StringBuffer s = new StringBuffer();
                for (int i = 1; i <= 4; i++) {
                    char c = str.charAt((int)(Math.random() * str.length()));
                    s.append(c);
                }

                g.setFont(new Font("微软雅黑", Font.BOLD, 70));
                g.setColor(Color.PINK);

                g.drawString(s.toString(), 100, 70);
            }
        }

        jf.add(new MyPaint());
//        jf.add(new MyPaint1());

        jf.setSize(700, 500);
        jf.setVisible(true);
        jf.setLocationRelativeTo(null);
        jf.setResizable(false);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}
